
import time
from utils.logger import get_logger

logger = get_logger()



def time_record(func):
    def wrapper(*args, **kwargs):
        start = time.time()
        result = func(*args, **kwargs)
        end = time.time()
        logger.info(f"方法 {func.__name__} 耗时: {end - start:.2f} 秒")
        return result
    return wrapper

class TimeMeta(type):
    def __new__(cls, name, bases, attrs):
        # 遍历类的所有属性，为方法添加装饰器
        for attr_name, attr_value in attrs.items():
            if callable(attr_value) and not attr_name.startswith("__"):
                attrs[attr_name] = time_record(attr_value)
        return super().__new__(cls, name, bases, attrs)

